package org.jeecg.modules.simulator.factory.park;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.parameter.api.entity.SimPark;
import org.jeecg.modules.parameter.biz.mapper.SimLineParkMapper;
import org.jeecg.modules.simulator.model.line.park.Parker;
import org.jeecg.modules.simulator.model.line.park.Parker1;
import org.jeecg.modules.simulator.model.line.park.load.ParkerLoader;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: simulator-b20240918
 * @description:
 * @author: renzhg
 * @create: 2024-10-14 17:07
 **/
@Slf4j
@Primary
@Service
public class SimParkerService  implements ParkerLoader {
    public static final  String PARKING="parking";
    public static final  String YARDS="yards";
    @Resource
    private SimLineParkMapper simLineParkMapper;

    @Getter
    Map<String, List<Parker>>  parkerMap=new HashMap<>();
    @Override
    public void loadParkData() {
        List<SimPark> simParkList = simLineParkMapper.selectList(null);
        List<Parker> parks=new ArrayList<>();
        for(SimPark simPark:simParkList){
            Parker parker=new Parker1();
            parker.setName(simPark.getParkName());
            parker.setUpOutStationId(simPark.getUpOut());
            parker.setDownOutStationId(simPark.getDownOut());
            parker.setId(simPark.getId());
            parker.setLineId(simPark.getMainLineId());
            parker.setOffset(Long.parseLong(simPark.getStartOffset()));
            if (simPark.getOperatingStatus().equals("01")) {
                parker.setOpen(true);
            } else {
                parker.setOpen(false);  // 如果条件为 false 执行的代码
            }
            parks.add(parker);
        }
        parkerMap= parks.stream().collect(Collectors.groupingBy(o -> o.getLineId()));
    }


}
